#!/bin/bash

source config/init_proj.sh

PROJECT_NAME="$PROJECT"
if [ ! -d Project/$PROJECT_NAME ];then
    echo "project name $PROJECT_NAME does not exist."
    exit 1
fi

while getopts "p:ru" arg
do
    case $arg in
        r)
            rm -rf build
            COMPILE_MODE=Release
            ;;
        u)
            COMPILE_MODE=Debug
            COMPILE_TARGET="--target ${PROJECT_NAME}_test.elf"
            ;;
        *)
            echo args error
            exit 1
            ;;
    esac
done

echo "PROJECT : $PROJECT_NAME"
echo "COMPILE MODE : ${COMPILE_MODE:=Debug}"
echo "PLATFORM : ${PLATFORM}"
cmake -B build -G"$CMAKE_GENERATOR" -DPLATFORM=$PLATFORM -DPROJECTNAME:STRING=$PROJECT_NAME -DCMAKE_BUILD_TYPE=$COMPILE_MODE
cmake --build build --parallel $(nproc) $COMPILE_TARGET